/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dal;

import thaihung.common.SQLQuery;
import java.sql.*;
/**
 *
 * @author bj
 */
public class DalDeThi {
    
    
    public static String LayDeThi(String MaDeThi) throws SQLException
    {
        SQLQuery sql = new SQLQuery();
        StringBuilder str = new StringBuilder();
        try
        {
            String query = "Select STT,NoiDung,A,B,C,D From CauHoi_DeThi ch_dt,CauHoi ch where ch_dt.MaDe = '" + MaDeThi + "' and ch_dt.MaCauHoi = ch.MaCauHoi";
            ResultSet rs = sql.ExcuteQR(query);
            while(rs.next())
            {
                str.append(rs.getInt(1));
                str.append("> ");
                str.append(rs.getString(2));
                str.append("\n     A : ");
                str.append(rs.getString(3));
                str.append("\n     B : ");
                str.append(rs.getString(4));
                str.append("\n     C : ");
                str.append(rs.getString(5));
                str.append("\n     D : ");
                str.append(rs.getString(5));
                str.append("\n\n");
            }
        }
        catch(SQLException ex)
        {
            throw ex;
        }
        return str.toString();
    }

    public static int SoLuongCH(String MaDeThi) throws SQLException{
        SQLQuery sql = new SQLQuery();
        int slCauHoi = -1;
        try {
            String lenh = "select * From CauHoi_DeThi where MaDe = '" + MaDeThi + "'";
            slCauHoi = sql.Count(lenh);
        } 
        catch (SQLException ex) {
            throw ex;
        }
        return slCauHoi;
    }

    public static int GetTGLamBai(String MaDeThi) throws SQLException {
        SQLQuery sql = new SQLQuery();
        int tgLamBai = -1;
        try {
            String lenh = "select ThoiGian From DeThi where MaDeThi = '" + MaDeThi + "'";
            tgLamBai = sql.ThoiGian(lenh);
        } 
        catch (SQLException ex) {
            throw ex;
        }
        return tgLamBai;
    }
}
